package com.pay.scheduler;

import com.pay.service.OmniAddressService;
import com.pay.service.OmniTransactionResService;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OmniScheduledService {
    @Autowired
    private OmniAddressService omniAddressService;
    @Autowired
    private OmniTransactionResService omniTransactionResService;

    @Scheduled(cron = "0 0 4 * * ?")
    @SchedulerLock(name = "listenWallet",lockAtLeastFor = 50 * 1000)
    public void listenWallet() throws Exception{
        omniAddressService.listenWallet();
    }

    /**
     * 節點事務掃描--包含
     * @throws Exception
     */
    @Scheduled(cron = "0 0/30 * * * ?")
    @SchedulerLock(name = "insertOrUpdateAddressWallet",lockAtLeastFor = 50 * 1000)
    public void insertOrUpdateAddressWallet() throws Exception{
        omniAddressService.insertOrUpdateAddressWallet();
    }

    /**
     * 節點事務掃描--包含
     * @throws Exception
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    @SchedulerLock(name = "insertOrUpdateTransactions",lockAtLeastFor = 50 * 1000)
    public void updateWalletAndTransactions() throws Exception{
        omniTransactionResService.updateWalletAndTransactions();
    }
}
